package cn.cdeden.knowledge.service;

import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.domain.TeamRelevanceRole;
import cn.cdeden.knowledge.domain.dto.FileUserDto;
import cn.cdeden.knowledge.domain.dto.FilesTree;
import cn.cdeden.knowledge.domain.dto.TeamRelevanceRoleDto;
import cn.cdeden.knowledge.domain.dto.TeamRelevanceRoleQueryParam;
import cn.cdeden.system.api.model.LoginUser;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Set;

/**
* @author Chen
* @date 2023-11-29
*/
public interface TeamRelevanceRoleService extends IService<TeamRelevanceRole> {

    static final String CACHE_KEY = "teamRelevanceRole";

    /**
    * 查询数据分页
    * @param query 条件
    * @param pageable 分页参数
    * @return PageInfo<TeamRelevanceRoleDto>
    */
    TableDataInfo<TeamRelevanceRoleDto> queryAll(TeamRelevanceRoleQueryParam query, Pageable pageable);

    /**
    * 查询所有数据不分页
    * @param query 条件参数
    * @return List<TeamRelevanceRoleDto>
    */
    List<TeamRelevanceRoleDto> queryAll(TeamRelevanceRoleQueryParam query);

    List<TeamRelevanceRoleDto> extendParentPerm(String parentId, String newTreeId);

    TeamRelevanceRole getById(Long id);

    /**
     * 判断权限方法
     * @param treeNodeId 树节点id
     * @param teamId 团队id
     * @param fileUserDto 用户
     * @param param 需要判断的权限
     * @return
     */
    Boolean checkPermission(String treeNodeId, String teamId, LoginUser fileUserDto, String param);

    List<FilesTree> checkPermissionByIds(String teamId, List<String> ids, Long userId, String param);


    /**
     * 获取关联的角色
     * @param treeNodeId 为null就是查询团队成员角色 不为null是查询对应文档
     * @param teamId 团队id
     * @param fileUserDto 用户
     * @return
     */
    List<TeamRelevanceRoleDto> getRole(String treeNodeId, String teamId, LoginUser fileUserDto);

    List<TeamRelevanceRoleDto> getRelevanceRoleByObject(String treeNodeId,String teamId,Long objectId,Integer objectType);

    void updateRole(String treeNodeId, Long objectId, Integer objectType, String roleId);
    TeamRelevanceRoleDto findById(Long id);

    /**
     * 插入一条新数据。
     */
    boolean insert(TeamRelevanceRoleDto resources);
    boolean updateById(TeamRelevanceRoleDto resources);
    boolean deleteById(Long id);
    boolean deleteByIds(Set<Long> ids);

    List<TeamRelevanceRole> getRelevanceRole(String teamId, Long id, List<String> treeNodeIds);

    List<TeamRelevanceRoleDto> getRelevanceRoleByTreeNodeId(String treeNodeId);

    void replaceOwnerPerm(Integer teamId, Long userId);

    void removeByTreeNodeId(String treeNodeId);

    List<TeamRelevanceRole> queryByOwner(String teamId,String objectId);

    void replaceOwnerOtherPerm(String teamId,String oldOwner, String newOwner);

    void removeExtend(Long treeNodeId, Long objectId);

    void removeByObjectIds(Integer teamId, Integer permTypeCode, Long objectIds);

    /**
    * 导出数据
    * @param all 待导出的数据
    * @param response /
    * @throws IOException /
    */
    // void download(List<TeamRelevanceRoleDto> all, HttpServletResponse response) throws IOException;
}
